Skip to content

Conversation

RobinMcCorkell
Copy link
Contributor

Follow up to #14785

ClientInterceptors should not be generic over request/response themselves, but rather should have generic methods: a given instance of this should be able to intercept any call, and so should have a generic method over all request/continuation types rather than the instance being specialized itself.

I also fixed the continuation/return types on the client interceptors which were incorrect:

  • The type of the second parameter to the continuation should be identical to the request/iterator given to the intercept call
  • The return type of the continuation should be identical to the return type of the intercept call
  • aio interceptor continuations are always Awaitable

The new tests demonstrate the correct usage.

Fixes: #14641

@RobinMcCorkell
Copy link
Contributor Author

@srittau one more for you :)

This comment has been minimized.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note on the tests: We don't run the tests, we only run type checkers against them, which is fairly expensive. Which is why we only use tests for weird corner cases and especially complex type annotations.

While the previous annotations were wrong, the new annotations aren't particular complex, so I don't think we need tests. The comments before the abstract methods should make the intent of the generics clear.

@RobinMcCorkell
Copy link
Contributor Author

RobinMcCorkell commented Oct 8, 2025

Fair point, I removed the new tests and expanded the comments to clarify the invariant that the types need to satisfy.

Copy link
Contributor

github-actions bot commented Oct 8, 2025

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@srittau srittau merged commit 0e10493 into python:main Oct 8, 2025
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grpcio: Interceptor base classes are incompatible with mypy --disallow-any-generics or --strict options

2 participants